]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Replace "round(x)" with "(int)(0.5 + x)"
authorSiegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
Thu, 1 Oct 2009 20:32:38 +0000 (22:32 +0200)
committerSiegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
Thu, 1 Oct 2009 20:39:04 +0000 (22:39 +0200)
round() is a C99 addition, so causes portability problems:
different C library versions require different #defines to
enable it. So simply avoid using it.

src/st/st-button.c
src/st/st-theme-node.c
src/st/st-widget.c

index a479e23add132b5b998ee73720ac4a5f5ed7d316..e1602e0863eb6ea11e514625abe9124e99673563 100644 (file)
@@ -35,7 +35,6 @@
 #include "config.h"
 #endif
 
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -165,7 +164,7 @@ st_button_style_changed (StWidget *widget)
 
   spacing = 6;
   st_theme_node_get_length (theme_node, "border-spacing", FALSE, &spacing);
-  priv->spacing = round (spacing);
+  priv->spacing = (int)(0.5 + spacing);
 
   /* update the label styling */
   st_button_update_label_style (button);
index ac2c1f7c17adf9b684dc3b7650e47a8acd326b5a..0b48e47e3918ceae2641542925ed12107c4053da 100644 (file)
@@ -1,6 +1,5 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -1565,7 +1564,7 @@ font_weight_from_term (CRTerm      *term,
       if (term->content.num->type != NUM_GENERIC)
         return FALSE;
 
-      weight_int = (int)(term->content.num->val + 0.5);
+      weight_int = (int)(0.5 + term->content.num->val);
 
       *weight = weight_int;
       *weight_absolute = TRUE;
@@ -1899,7 +1898,7 @@ st_theme_node_get_border_image (StThemeNode *node)
 
               if (term->content.num->type == NUM_GENERIC)
                 {
-                  borders[n_borders] = round (0.5 + term->content.num->val);
+                  borders[n_borders] = (int)(0.5 + term->content.num->val);
                   n_borders++;
                 }
               else if (term->content.num->type == NUM_PERCENTAGE)
@@ -1962,15 +1961,15 @@ st_theme_node_get_border_image (StThemeNode *node)
 static float
 get_width_inc (StThemeNode *node)
 {
-  return (round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] +
-          round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
+  return ((int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] +
+          (int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
 }
 
 static float
 get_height_inc (StThemeNode *node)
 {
-  return (round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] +
-          round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
+  return ((int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] +
+          (int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
 }
 
 /**
@@ -2103,10 +2102,10 @@ st_theme_node_get_content_box (StThemeNode           *node,
 
   ensure_borders (node);
 
-  content_box->x1 = round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
-  content_box->y1 = round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
-  content_box->x2 = allocation->x2 - allocation->x1 - (round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
-  content_box->y2 = allocation->y2 - allocation->y1 - (round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
+  content_box->x1 = (int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
+  content_box->y1 = (int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
+  content_box->x2 = allocation->x2 - allocation->x1 - ((int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
+  content_box->y2 = allocation->y2 - allocation->y1 - ((int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
 }
 
 
index 6605ce7595c8b7f5c80c04433b5c096ea91fd408..02c57cc4451fef8bc6cd62a0abb74d6e9ee7c244 100644 (file)
@@ -28,7 +28,6 @@
 #include "config.h"
 #endif
 
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -533,7 +532,7 @@ st_widget_real_style_changed (StWidget *self)
       double width = st_theme_node_get_border_width (theme_node, side);
       if (width > 0.5)
        {
-         border_width = round (width);
+         border_width = (int)(0.5 + width);
          st_theme_node_get_border_color (theme_node, side, &border_color);
          break;
        }
@@ -544,7 +543,7 @@ st_widget_real_style_changed (StWidget *self)
       double radius = st_theme_node_get_border_radius (theme_node, corner);
       if (radius > 0.5)
        {
-         border_radius = round (radius);
+         border_radius = (int)(0.5 + radius);
          break;
        }
     }